﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TJADRICD.Model;
using TJADRICD.DLL;

namespace TJADRICD.CollaborativeDesignPlugin.Commission
{
    class SignCommissionUser
    {
        public String userId { get; set; }
        public String userName { get; set; }
        public int ComboxNameIndex;
    }
    class DBCommissionRecord
    { 
        public String commissionId ;
        public String commissionedId;
        public DateTime startDate;
        public DateTime finishDate;
    }
    class CommandSignCommission
    {
        List<SignCommissionUser> commissionedList = null;
        SignCommissionUser commissionedUser = null;
        private AuthorizeDao auDao = null;
        private AccountDao acDao = null;

        public CommandSignCommission()
        {
            commissionedList = new List<SignCommissionUser>();
            auDao = new AuthorizeDao();
            acDao = new AccountDao();
        }
        public List<SignCommissionUser> GetCommissionedList(String commissionId)
        {
            List<Authorize> auList = new List<Authorize>();
            auList = auDao.getAuthorListByUser(commissionId);
            foreach (Authorize auEntity in auList)
            {
                SignCommissionUser user = new SignCommissionUser();
                user.userId = auEntity.AuthId;
                user.userName = acDao.getUserNameById(user.userId);
                commissionedList.Add(user);
            }
            return commissionedList;
        }

        public void AddCommissionRecord(DBCommissionRecord commissionRecord)
        {
            Authorize auEntity = new Authorize();
            auEntity.RoleMajorId = commissionRecord.commissionId;
            auEntity.AuthId = commissionRecord.commissionedId;
            auEntity.StartDate = commissionRecord.startDate;
            auEntity.FinishDate = commissionRecord.finishDate;
            auDao.insertAuthorRecord(auEntity);
        }
        public SignCommissionUser FindCommissionedUser(String commissionedName)
        {
            commissionedUser = null;
            String userId = acDao.getUserIdByUserName(commissionedName);
            if (userId != null)
            {
                commissionedUser = new SignCommissionUser();
                commissionedUser.userId = userId;
                commissionedUser.userName = commissionedName;
            }
            return commissionedUser;
        }
    }
}
